1. Field of the Invention
This invention generally relates to database systems for computers and, more particularly, to an apparatus and methods for creating indexes in a relational database corresponding to classes in an object-oriented application.
2. Description of the Related Art
Object-database mapping tools assist in integrating tables in a database to corresponding classes in an object-oriented application. Conventional object-database mapping tools receive class definitions from an object-oriented application and automatically generate code, typically stored in a database schema, to create tables and other structures for the database. The tables and structures in the database are used to hold data corresponding to objects generated by an object-oriented application.
There are numerous challenges to improve the techniques for mapping object-oriented applications and databases in the object-database mapping tools. These techniques need to account for the organization of data in an object-oriented application compared with the organization of data in a database.
In an object-oriented application the skeleton of an object is a class. The class may have a number of fields used to store values or states typically used by object instances of the class. The class may also include specific methods which define how objects instantiated from each class will interact with each other and hold certain information in each of the corresponding fields. A hierarchical class structure provides an organized framework for creating objects and their relationships.
In contrast, databases have features that object-oriented applications do not possess. The database typically organizes data using one or more tables having multiple rows and columns. A data relationship is defined by the manner in which data is stored in the various rows and columns of the tables. A single table or multiple tables can be used to hold every row or record of data. A primary key includes one or more columns in a table that uniquely define each row of data. If multiple tables are used to store a data, a foreign key associates rows of data in one table with another table.
Unlike classes in an object-oriented application, databases index columns of data for fast access. Each database index is made on columns of data contained in a single table. Conventional mapping tools do not provide the object-oriented user a generalized technique for specifying how an index should be generated in a database. In many cases, the object-oriented user would have to have database programming skills to manually generate indexes in the database. This could become a complex process requiring the object-oriented user to create several indexes depending on the mapping of objects into the database. For example, the user may be required to generate several different indexes if several fields in an object correspond to several tables in a database. In these more complex situations, conventional object-database mapping tools are difficult to use. These tools require the object-oriented user to understand databases and manually generate indexes. Finding such a knowledgeable user is generally difficult. Moreover, the object-oriented user must also understand how fields in classes map to columns in tables of a database and the data processing trade-offs in generating several different indexes. For at least these reasons, optimizing data processing performance with database indexes is a difficult process using conventional object-database mapping tools. As a result, the cost and complexity of integrating object-oriented systems and databases can increase significantly.
Based on the above limitations found in conventional database and object-oriented systems, it is desirable to improve the methods and systems for creating indexes in a database corresponding to fields in an object-oriented application.
In accordance with methods and systems consistent with the present invention, an improved object-database mapping tool is provided that generates indexes in a database corresponding to classes in an object-oriented application. Initially, the mapping tool maps each class in an object-oriented application to a table in a database. A user, for example, selects one or more fields to be indexed from one or more classes. The tool determines if the selected fields correspond to the columns in more than one table in the database. If the selected fields correspond to a plurality of tables in the database then the mapping tool generates a plurality of indexes. Alternatively, if the fields correspond to one table in the database then the mapping tool generates a single index.